﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lopet.Repositories
{
    public class RandomNumberRepository
    {   
        private static Random _random;

        private static RandomNumberRepository _instance;

        private RandomNumberRepository() 
        {
            _random = new Random(1021);
        }

        public static RandomNumberRepository Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new RandomNumberRepository();
                }
                return _instance;
            }
            set 
            {
                _instance = null;
            }
        }

        public Random GetRandomClass()
        {
            return _random;
        }

        public double NextDouble 
        {
            get
            {
                lock (this)
                {
                    return _random.NextDouble();                    
                }
            }
        }

        public int NextInt(int min, int max)
        {
            var rand = NextDouble;
            return (int)((max - min) * rand + min);
        }
    }
}
